package cn.com.gridinfo.sooc.utils.widget;

import android.content.Context;
import android.support.annotation.NonNull;

import com.afollestad.materialdialogs.DialogAction;
import com.afollestad.materialdialogs.MaterialDialog;

import cn.com.gridinfo.sooc.R;

/**
 * Created by Michelle on 2016/1/12.
 */
public class MyMaterialDialog {
    /**
     * MaterialDialog
     * @param context
     * @param title
     * @param content
     */
    public static void showMaterialDialog(Context context,String title,String content){
        showMaterialDialog(context,title,content,null,null,null,null,true);
    }


    /**
     * MaterialDialog
     * @param context
     * @param content
     * @param negativeText
     * @param negtiveClickListener
     * @param positiveText
     * @param positiveClickListener
     * @param cancelable
     */
    public static void showMaterialDialog(Context context,String content,String negativeText,MaterialDialog.SingleButtonCallback negtiveClickListener,
                                          String positiveText,MaterialDialog.SingleButtonCallback positiveClickListener,
                                          boolean cancelable){
        showMaterialDialog(context,null,content,negativeText,negtiveClickListener,positiveText,positiveClickListener,cancelable);

    }

    /**
     * MaterialDialog
     * @param context
     * @param title
     * @param content
     * @param negativeText
     * @param negtiveClickListener
     * @param positiveText
     * @param positiveClickListener
     */
    public static void showMaterialDialog(Context context,String title,String content,
                                          String negativeText,MaterialDialog.SingleButtonCallback negtiveClickListener,
                                          String positiveText,MaterialDialog.SingleButtonCallback positiveClickListener
                                          ){
        showMaterialDialog(context,title,content,negativeText,negtiveClickListener,positiveText,positiveClickListener,true);
    }

    /**
     * MaterialDialog
     * @param context
     * @param title
     * @param content
     * @param negativeText
     * @param negtiveClickListener
     * @param positiveText
     * @param positiveClickListener
     * @param cancelable
     */
    public static void showMaterialDialog(Context context,String title,String content,
                                          String negativeText,MaterialDialog.SingleButtonCallback negtiveClickListener,
                                          String positiveText,MaterialDialog.SingleButtonCallback positiveClickListener,
                                          boolean cancelable){
        MaterialDialog.Builder dialog =  new MaterialDialog.Builder(context);
        dialog.backgroundColorRes(R.color.white);
        if(title != null){
            dialog.title(title).titleColorRes(R.color.color_tv333);
        }
        if(content != null){
            dialog.content(content).contentColorRes(R.color.color_666);
        }
        if(negativeText != null){
            dialog.negativeText(negativeText)
                    .negativeColorRes(R.color.color_666);
        }
        if(negtiveClickListener != null){
            dialog.onNegative(negtiveClickListener);
        }else{
            dialog.onNegative(new MaterialDialog.SingleButtonCallback() {
                @Override
                public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                    dialog.cancel();
                }
            });
        }
        if(positiveText != null){
            dialog.positiveText(positiveText)
                    .positiveColorRes(R.color.colorPrimary);
        }
        if(positiveClickListener != null){
            dialog.onPositive(positiveClickListener);
        }else{
            dialog.onPositive(new MaterialDialog.SingleButtonCallback() {
                @Override
                public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                    dialog.dismiss();
                }
            });
        }
        dialog.cancelable(cancelable)
                .show();
    }
}
